<%@page import="cn.com.dhcc.app.pub.core.consts.NodeInfoParam"%>
<%@page import="cn.com.dhcc.app.core.AppEnv"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<script type="text/javascript" src="${ctx}/static/js/lib/jquery.cookie.js"></script>
<%@ include file="/WEB-INF/view/common/auth.jsp"%>
<%
pageContext.setAttribute("version", AppEnv.InitCtx.version);
pageContext.setAttribute("manager", NodeInfoParam.isManaagerNode());
%>
<script type="text/javascript">
	var home_timerid=-1;
	jQuery(function($) {
		var needSound = $.cookie("needSound");
		if(needSound!='false'){
			  $("#bell_on").css("display","none");
			  $("#bell_off").css("display","");
		}else{
			  $("#bell_on").css("display","");
			  $("#bell_off").css("display","none");
		}
		window.clearTimeout(home_timerid);
		loadData();
		timerid  = window.setInterval("loadData()",5000);
	});
	function loadData(){
			$.jsonGet({
				   type: "POST",
				   dataType:"json",
				   cache: false,
				   url: _ctx + "/monitor/load_data.do",
				   jsonStatusSuccessCall: function(msg,data){
					   var sum =0;
					   var shows = eval('(' + msg + ')');
						for ( var i = 0; i < shows.length; i++) {
							var json = shows[i];
							var code =  json.code;
							var value = json.value;
							sum = sum + value;
							$("#" + code).html(value);
						}
						var needSound = $.cookie("needSound");
						if(needSound!='false' && sum>0){
							document.getElementById("bgsound").src="${ctx}/static/sound/alert.mp3";
						}else {
							document.getElementById("bgsound").src="";
						}
				   },
				   jsonStatusFailCall:function(msg,data){
					   ui.msg(msg, 0);
				   },
				   error:function(){
					   //
				   }
				  
			});
	}
	 function openSound(){
		  $.cookie("needSound",null, {path:"/"});
		  $("#bell_on").css("display","none");
		  $("#bell_off").css("display","");
	  }
	  function closeSound(){
		  var dayToColse = 1;//24 hour
		  $.cookie("needSound", "false", {expires:dayToColse,path:"/"});
		  document.getElementById("bgsound").src="";
		  $("#bell_on").css("display","");
		  $("#bell_off").css("display","none");
		  ui.msg("24小时内将不再播放告警音！",1);
	  }
	function passwordChange() {
		$.ajax({
			type : "GET",
			dataType : "html",
			cache : false,
			url : _ctx + "/account/password_change.do",
			success : function(content) {
				$('#passwordChange').html(content);
				$('#passwordChangeModal').modal('show');
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	}
	
	/**
	 * 检查新密码是否合乎规范后更改新密码
	 */
	function checkSubmit(){
		var oldPassword = document.getElementById("oldPassword").value;
		var newPassword = document.getElementById("newPassword").value;
		var confirmPassword = document.getElementById("confirmPassword").value;
		if(oldPassword!=0){
			if(newPassword!=0){
				if(confirmPassword!=0){
					if(newPassword.length<25 && newPassword.length>4){
						if(isPassWord(newPassword,confirmPassword) == true){
							changePassword();
						}else{
							alert("两次输入的密码不一致！");
						}
					}else{
						alert("密码长度必须在5-25个字符之间！");
					}
				}else{
					alert("您还没有填写确认密码!");
				}
			}else{
				alert("请您先填写新密码！");
			}
		}else{
			alert("请您先填旧密码！");
		}
	}

	/**
	 * 判断两次输入的新密码是否相同
	 */
	function isPassWord(passWord,passWordDemo){

		var newPassword = document.getElementById("newPassword").value;
		var confirmPassword = document.getElementById("confirmPassword").value;

		if(confirmPassword　!= newPassword){
			document.getElementById('spantest').innerText = "两次输入的密码不一致！ ";
			newCheck = false;
			return false;
		}else{
			newCheck = true;
			return true;
		}
	}

	/**
	 * 更改新密码
	 */
	function changePassword() {
		$.ajax({
			type : "POST",
			dataType : "json",
			cache : false,
			url : _ctx + "/account/password_do_change.do",
			data : {
				oldPassword : $("#oldPassword").val(),
				newPassword : $("#newPassword").val(),
			},
			success : function(content) {
				if (content.status == '1') {
					ui.msg(content.msg, 1);
				} else {
					ui.msg(content.msg, 0);
				}
				$('#passwordChangeModal').modal('hide');
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	}
</script>
<bgsound id="bgsound" loop="infinite" autostart="true">
<div class="navbar navbar-default" id="navbar">
	<div class="navbar-container" id="navbar-container" style="z-index: 999;">
		<div class="navbar-header pull-left">
			<a href="#" class="navbar-brand" style="padding-bottom: 0px;">
				<img alt="" src="${ctx}/static/images/logo-water.png" width="30px;">
				<small>
					<span style="font-family:'黑体'">
					${appname}<font size="3px">(<c:if test="${!empty sessionScope._local_node_session}">${sessionScope._local_node_session.nodeName}-</c:if>${si:ctname("NET_TYPE",sessionScope._netType)})
					</font>
					<font size="2px">&nbsp;${version}</font>
				</span></small>
				<c:if test="${manager}" >
					 <img src="${ctx}/static/images/mgr.png" style="width: 18px;padding-top:3px;"></img>
					</c:if>
			</a>
		</div>
		<div class="navbar-header pull-right" role="navigation">
			<ul class="nav ace-nav">
			<c:if test="${sessionScope._user_session.slAuthFlag ne 4 }">
				<li class="orange" id="topbar1">
					<a class="dropdown-toggle" href="${ctx}/exch/alert_list.do">
						<i class="icon-bell-alt icon-animated-bell"></i>
						<span class="badge badge-important"  id="countAlert"></span>
					</a>
				</li>
			</c:if>
				<c:if test="${sessionScope._user_session.slAuthFlag ne 4 }">
						<li class="green" id="topbar2">
							<a class="dropdown-toggle" href="${ctx}/monitor/carved_discs_manage_list.do">
								<i class="icon-hdd icon-animated-vertical"></i>
								<span class="badge badge-success"  id="carvedDiscsSumReq"></span>
							</a>
						</li>
				</c:if>
				<li class="light-blue">
					<a data-toggle="dropdown" href="#" class="dropdown-toggle" >
						<span class="user-info">
						<small>欢迎您！</small>
						${sessionScope._user_session.userNameStr}
						</span>
						<i class="icon-caret-down"></i>
					</a>
					<ul class="user-menu pull-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
						<li id="topbar3">
							<a href="#" onclick="passwordChange();">
							<i class="icon-user"></i>
							修改登录密码
							</a>
						</li>
						<li class="divider"></li>
						<li >
							<a href="javascript:void(0)" onclick="javascript:ui.confirm('确定要退出么?',function(){self.location='${ctx}/account/logout.do';});">
							<i class="icon-off"></i>
							退出
							</a>
						</li>
					</ul>
				</li>
			</ul>
		</div>
	</div>
</div>
<div id="passwordChangeModal" class="modal fade" role="dialog" tabindex="-1" aria-labelledby="查看" aria-hidden="false">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class='widget-header widget-header-small'><h5 class='smaller'> 密码修改</h5></div>
			<div id="passwordChange"></div>
		</div>
	</div>
</div>
